home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / graphics / AutoDrawArea_test.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  5.2 KB  |  197 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/testprgs/graphics/AutoDrawArea_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.7 $
  9.  *    $Date: 1994/07/23 19:14:49 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. extern "C" {
  16. #include <dos/dos.h>
  17. }
  18. #include <APlusPlus/exec/SignalResponder.h>
  19. #include <APlusPlus/intuition/GWindow.h>
  20. #include <APlusPlus/graphics/AutoDrawArea.h>
  21. #include <APlusPlus/intuition/IntuiMessageC.h>
  22. #include <APlusPlus/graphics/GBorder.h>
  23.  
  24. #include <iostream.h>
  25.  
  26. static const char rcs_id[] = "$Id: AutoDrawArea_test.cxx,v 1.7 1994/07/23 19:14:49 Armin_Vogt Exp Armin_Vogt $";
  27.  
  28.  
  29. BOOL running = TRUE;
  30. BOOL close2 = FALSE;
  31.  
  32. class MySRSP : public SignalResponder
  33. {
  34.    public:
  35.       MySRSP(BYTE signal) : SignalResponder(signal,0) {}
  36.       ~MySRSP() {}
  37.       // overload the virtual 'signal received' action callback method.
  38.       void actionCallback()
  39.       {
  40.          cout << "**Break\n";
  41.          running = FALSE;
  42.       }
  43. };
  44.  
  45. // This customized AutoDrawArea class draw somethin within its boundary box
  46. // according to its personal 'drawSelf()' method.
  47. // Create as much of these as you like within a GWindow - they will all look
  48. // the same.
  49.  
  50. class MyAutoDrawArea : public AutoDrawArea
  51. {
  52.    public:
  53.       MyAutoDrawArea(GraphicObject *owner,AttrList& attrs) : AutoDrawArea(owner,attrs) { }
  54.       ~MyAutoDrawArea() {}
  55.  
  56.       void drawSelf()
  57.       {
  58.          setDrMd(JAM2);
  59.          setDrPt(~0);
  60.          setAPen(2);
  61.          setOPen(3);
  62.          rectFill(0,0,iWidth()-1,iHeight()-1);
  63.          setAPen(3);
  64.          drawEllipse(iWidth()/2,iHeight()/2,iWidth()/2,iHeight()/2);
  65.          setAPen(1);
  66.          WORD polyTable[] = {10,10,40,10,40,40,10,40,10,10};
  67.          polyDraw(5,polyTable);
  68.       }
  69.       
  70.       // runtime type inquiry support
  71.       static const Intui_Type_info info_obj;
  72.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  73.          { return info_obj; }
  74.       static const Type_info& info()                // get the 'type_id' of a specific class
  75.          { return info_obj; }
  76.  
  77. };
  78.  
  79. intui_typeinfo(MyAutoDrawArea, derived(from(AutoDrawArea)), rcs_id);
  80.  
  81.  
  82. class MyWindow : public GWindow
  83. {
  84.    private:
  85.       void init();
  86.  
  87.    public:
  88.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs) { init(); }
  89.  
  90.  
  91.       void On_CLOSEWINDOW(const IntuiMessageC *msg)
  92.       {
  93.          cout << "CLOSEWINDOW.\n";
  94.          delete this;
  95.          running = FALSE;
  96.       }
  97.       void On_ACTIVEWINDOW(const IntuiMessageC *msg)
  98.       {
  99.          cout << title() << " is ACTIVE.\n";
  100.       }
  101.       void On_SIZEVERIFY(const IntuiMessageC *msg)
  102.       {
  103.          cout << "SIZEVERIFY. \n";
  104.       }
  105.       virtual void handleIntuiMsg(const IntuiMessageC* imsg)
  106.       {
  107.          switch (imsg->getClass())
  108.          {
  109.             case CLASS_CLOSEWINDOW :
  110.                On_CLOSEWINDOW(imsg); break;
  111.             case CLASS_ACTIVEWINDOW :
  112.                On_ACTIVEWINDOW(imsg); break;
  113.             case CLASS_SIZEVERIFY :
  114.                On_SIZEVERIFY(imsg); break;
  115.          }
  116.          GWindow::handleIntuiMsg(imsg);
  117.       }
  118.  
  119.       // runtime type inquiry support
  120.       static const Intui_Type_info info_obj;
  121.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  122.          { return info_obj; }
  123.       static const Type_info& info()                // get the 'type_id' of a specific class
  124.          { return info_obj; }
  125.       
  126. };
  127.  
  128. intui_typeinfo(MyWindow, derived(from(GWindow)), rcs_id);
  129.  
  130.  
  131. void MyWindow::init()
  132. {
  133.    modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_SIZEVERIFY);
  134. }
  135.  
  136.  
  137. void APPmain(int argc,char* argv[])
  138. {
  139.    MySRSP sr(SIGBREAKB_CTRL_C);
  140.  
  141.  
  142.    NeXTBorder lineBorder;
  143.  
  144.  
  145.    MyWindow *little = new MyWindow(OWNER_NULL,
  146.    AttrList( WA_Title,"WindowC - close this to stop.",
  147.       WA_Left,300,
  148.       WA_Top,200,
  149.       WA_Width,300,
  150.       WA_Height,150,
  151.       WA_MinHeight,100,
  152.       WA_MinWidth,200,
  153.       WA_MaxHeight,1600,
  154.       WA_MaxWidth,1600,
  155.       WA_DragBar,TRUE,
  156.       WA_SizeGadget,TRUE,
  157.       WA_DepthGadget,TRUE,
  158.       WA_CloseGadget,TRUE,
  159.       WA_IDCMP,IDCMP_CLOSEWINDOW,
  160.       GOB_BorderObj(&lineBorder),
  161.       GOB_BorderTitle, (UBYTE*)" AutoDrawArea ",
  162.       GOB_BackgroundColor, 4,
  163.       TAG_END) );
  164.  
  165.    new MyAutoDrawArea(little,
  166.    AttrList( GOB_LeftFromLeftOfParent,0,
  167.              GOB_TopFromTopOfParent,0,
  168.              GOB_RightFromRightOfParent,0,
  169.              GOB_BottomFromBottomOfParent,0,
  170.              TAG_END) );
  171.  
  172.    new MyAutoDrawArea(little,
  173.    AttrList( GOB_LeftFromRightOfParent,-50,
  174.              GOB_TopFromTopOfParent,10,
  175.              GOB_RightFromRightOfParent,-10,
  176.              GOB_BottomFromBottomOfParent,-1,
  177.              GOB_BorderObj(&lineBorder),
  178.              TAG_END) );
  179.  
  180.    new MyAutoDrawArea(little,
  181.    AttrList( GOB_LeftFromLeftOfPred,-50,
  182.              GOB_TopFromTopOfParent,10,
  183.              GOB_RightFromLeftOfPred,-1,
  184.              GOB_BottomFromBottomOfParent,-2,
  185.              GOB_BorderObj(&lineBorder),
  186.              TAG_END) );
  187.  
  188.    little->refreshGList();    // display objects
  189.  
  190.    while (running)
  191.    {
  192.       SignalResponder::WaitSignal();
  193.    }
  194.  
  195.    cout << "cleaned up. goodbye.\n";
  196. }
  197.